var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');
// var pageAdmin = require('./auth/auth');
// var multer  = require('multer')
// var upload = multer({ dest: 'uploads/' })


var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
// 可以修改为html
// app.engine('.html',require('ejs').__express);
//
// app.set('view engine','html');
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

//定义路由位置
var index = require('./routes/index');
var login = require('./routes/login');
// var users = require('./routes/users/users');
var car = require('./routes/car/index');
var home = require('./routes/home/index');
var terminal = require('./routes/terminal/index');
var combData = require('./routes/comb/index');
//测试
var baseDemo = require('./routes/demo/index');
var map = require('./routes/map/index');
var cusTree = require('./routes/tree/index');
var cusUpload = require('./routes/upload/index');

//生成代码
var baseCar = require('./routes/baseCar/index');
var baseCarCommonSet = require('./routes/baseCarCommonSet/index');
var baseCarType = require('./routes/baseCarType/index');
var baseCommonFence = require('./routes/baseCommonFence/index');
var baseFenceManager = require('./routes/baseFenceManager/index');
var baseWorkInfo = require('./routes/baseWorkInfo/index');
var busTerminalData = require('./routes/busTerminalData/index');
var busTerminalHisData = require('./routes/busTerminalHisData/index');
var tabWaringInfo = require('./routes/tabWaringInfo/index');
var baseTerminal = require('./routes/baseTerminal/index');
var report = require('./routes/report/index');

var baseDriver = require('./routes/baseDriver/index');
var baseCarKeep = require('./routes/baseCarKeep/index');
var baseWorkManager = require('./routes/baseWorkManager/index');
var busPassLine = require('./routes/busPassLine/index');
var cusexcel = require('./routes/excel/index');
//资料管理
var dataManage = require('./routes/dataManage/dataManage');
//编辑用户管理信息
var editUserInfo = require('./routes/dataManage/editUserInfo');
var accountManage = require('./routes/dataManage/accountManage');
var editAccountInfo =require('./routes/dataManage/editAccount');
var deviceManage = require('./routes/dataManage/deviceManage');
var editDeviceInfo = require('./routes/dataManage/editDeviceInfo');
var roleManage = require('./routes/dataManage/roleManage');
var editRoleInfo  = require('./routes/dataManage/editRoleInfo');
var newHis = require('./routes/map/newHis');
var editFastDeviceInfo = require('./routes/dataManage/fastEditDeviceInfo');
//监控管理
var monitorManage = require('./routes/map/monitor');
var applicationManage = require('./routes/applicationManage/applicationManage');
var systemManage = require('./routes/systemManage/systemManage');
var moreDataSetting = require('./routes/systemManage/moreDataSetting');
var electronManage = require('./routes/applicationManage/electronManage');
var reportManage = require('./routes/report/reportManage');
var chaosureportManage = require('./routes/report/chaosureportManage');
var stopcarreportManage = require('./routes/report/stopcarreportManage');
var jingqingreportManage = require('./routes/report/jingqingreportManage');
var runreportManage = require('./routes/report/runreportManage');
var hotportManage = require('./routes/report/hotportManage');
var fengkongreportManage = require('./routes/report/fengkongreportManage');
var mainFrame = require('./routes/mainFrame');
var powerSetting = require('./routes/systemManage/powerSetting');
app.use(session({
    secret: 'sskj-lvpeng-zcl',//与cookieParser中的一致
    resave: true,
    saveUninitialized:true,
    cookie: { secure: false }
}));
app.use('/', login);
app.use('/index', index);
app.use('/mainFrame', mainFrame);
// 测试
// app.use('/users', users);
app.use('/car', car);

//首页
app.use('/home', home);
//终端管理
app.use('/terminal', terminal);
app.use('/combData', combData);
//测试
app.use('/demo', baseDemo);
// 地图
app.use('/map', map);
// tree
app.use('/tree', cusTree);
app.use('/upload', cusUpload);
app.use('/report', report);

// 生成代码
app.use('/baseCar', baseCar);
app.use('/baseCarCommonSet', baseCarCommonSet);
app.use('/baseCarType', baseCarType);
app.use('/baseCommonFence', baseCommonFence);
app.use('/baseFenceManager', baseFenceManager);
app.use('/baseWorkInfo', baseWorkInfo);
app.use('/busTerminalData', busTerminalData);
app.use('/busTerminalHisData', busTerminalHisData);
app.use('/tabWaringInfo', tabWaringInfo);
app.use('/baseTerminal', baseTerminal);
app.use('/baseWorkManager', baseWorkManager);
app.use('/baseDriver', baseDriver);
app.use('/baseCarKeep', baseCarKeep);
app.use('/busPassLine', busPassLine);
app.use('/excel', cusexcel);
app.use('/dataManage',dataManage);
app.use('/monitor',monitorManage);
app.use('/editUserInfo',editUserInfo);
app.use('/accountManage',accountManage);
app.use('/editAccountInfo',editAccountInfo);
app.use('/deviceManage',deviceManage);
app.use('/editDeviceInfo',editDeviceInfo);
app.use('/roleManage',roleManage);
app.use('/editRoleInfo',editRoleInfo);
app.use('/newHis',newHis);
app.use('/editFastDeviceInfo',editFastDeviceInfo);
app.use('/applicationManage',applicationManage);
app.use('/systemManage',systemManage);
app.use('/moreDataSetting',moreDataSetting);
app.use('/electronManage',electronManage);
app.use('/reportManage',reportManage);
app.use('/chaosureportManage',chaosureportManage);
app.use('/stopcarreportManage',stopcarreportManage);
app.use('/runreportManage',runreportManage);
app.use('/jingqingreportManage',jingqingreportManage);
app.use('/hotportManage',hotportManage);
app.use('/fengkongreportManage',fengkongreportManage);
app.use('/powerSetting',powerSetting);
// catch 404 and forward to error handler
//sockio
//var http=require("http");//引入express
//var socketIo=require("socket.io");//引入socket.io
//var appEx=new express();
//var server=http.createServer(appEx);
//var io=new socketIo(server);

app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});


// error handler
app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);
  res.render('error');
});



module.exports = app;
// module.exports = function (app) {
//     app.get('/user/blogList',pageAdmin.checkAuth, pageAdmin.pageList);
//     app.all('/user/post',pageAdmin.checkAuth, pageAdmin.pagePost);
// }